package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWLabel;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWTabControl;
import com.handinfo.android.uicontrols.controls.DWTabPage;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UINeiDanWindow implements IUIWindows
{
	private static final byte mNeiDanLi = 0; //力丹
	private static final byte mNeiDanZhi = 1; //智丹
	private static final byte mNeiDanJi = 2; //技丹
	private static final byte mNeiDanMin = 3; //敏丹
	public byte neiDanTypeNum = 4;

	private byte mNeiDanLiYES[]; //力丹 每个等级开启数
	private byte mNeiDanLiNOE[]; //力丹  每个等级可以开启是数
	private byte mNeiDanLiGongXiao[]; //力丹  每个等级 一个内丹的功效
	private int mNeiDanLiZhangGong[]; //每级消耗的战功

	private byte mNeiDanZhiYES[]; //智丹 每个等级开启数
	private byte mNeiDanZhiNOE[]; //智丹  每个等级可以开启是数
	private byte mNeiDanZhiGongXiao[]; //力丹  每个等级 一个内丹的功效
	private int mNeiDanZhiZhangGong[];//每级消耗的战功

	private byte mNeiDanJiYES[]; //技丹 每个等级开启数
	private byte mNeiDanJiNOE[]; //技丹  每个等级可以开启是数
	private byte mNeiDanJiGongXiao[]; //技丹  每个等级 一个内丹的功效
	private int mNeiDanJiZhangGong[];//每级消耗的战功

	private byte mNeiDanMinYES[]; //敏丹 每个等级开启数
	private byte mNeiDanMinNOE[]; //敏丹  每个等级可以开启是数
	private byte mNeiDanMinGongXiao[]; //敏丹  每个等级 一个内丹的功效
	private int mNeiDanMinZhangGong[];//每级消耗的战功

	Bitmap m_cr_tab_1 = null;// 点击前图片
	Bitmap m_cr_tab_2 = null;// 点击后图片
	Bitmap m_cr_noeat = null;
	Bitmap m_cr_tc = null; // 退出叉键按钮的图片
	Bitmap m_cr_xxbj = null;
	Bitmap m_cr_dan[] = new Bitmap[4];
	Bitmap m_cr_dan_2 = null; ////点击后的丹
	Bitmap m_cr_xiamian = null; ////最下面的

	DWFrame m_neidan_Frame = null;
	DWTitle m_neidan_tit;
	public DWTabControl m_tabcontrol = null;
	DWBackground m_xbj_bg; // ////小背景的
	DWBackground m_zuo_xiamian_bg;////最下面的左侧的
	DWBackground m_you_xiamian_bg;////最下面的右侧的
	DWBackground m_zuo_bg; //左侧的中国结
	DWBackground m_you_bg; ///右侧的中国结

	DWImageBox m_dan_qian[][];
	DWImageBox m_tc_ima; // /退出叉键按钮
	DWButton m_but;
	DWListSubItem m_listsubitem1;
	DWListSubItem m_listsubitem2;
	DWListbox[] m_listbox_data = null;
	DWTextbox[] m_textbox = new DWTextbox[4];
	DWLabel m_lv_label;
	DWLabel m_textbox_data[] = new DWLabel[4];
	DWTextbox m_text_data_text[] = new DWTextbox[4];
	DWLabel m_label;
	DWLabel m_zuo_textbox;
	DWLabel m_you_textbox;
	long m_sum_1 = 0;
	long m_sum_2 = 0;
	long m_sum_3 = 0;
	long m_sum_4 = 0;
	int i;
	int j;
	int k;
	int m;
	byte m_save_listbox_item_dengji_index;
	// //标签页按钮的名字数组
	String[] m_stringname = new String[] { "力丹", "智丹", "技丹", "敏丹" };
	String m_name[] = new String[] { "力量: ", "智力: ", "技巧: ", "敏捷: " };
	String m_name_1[] = new String[] { "力", "智", "技", "敏" };
	long[] m_sum;
	DWTextbox m_tb; ///每一个subitem里放的textbox 
	DWTabPage m_tp[] = new DWTabPage[m_stringname.length];
	byte[] m_list_1 = null;
	byte[] m_list_2 = null;
	byte[] m_list_3 = null;
	byte m_save_biaoqian_index = 0;
	DWImageBox m_tit_ima;
	Bitmap m_cr_tit = null;
	/**** 对话框 *****/
	DWFrame m_tishi_Frame = null;
	Bitmap m_cr_but_1 = null;
	Bitmap m_cr_but_2 = null;
	DWBackground m_tishi_xbj_bg; ///小背景
	byte m_list[] = null;///为了新手教学
	DWListSubItem m_lsi[][];
	/**
	 * 内丹开启界面数据接收
	 * @param dis
	 */
	byte maxLevel;

	public void recvNeiDanOpenWin(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_内丹);
		maxLevel = dis.readByte(); //最大等级
		for (int i = 0; i < neiDanTypeNum; i++) {
			byte neiDan_type = dis.readByte();
			byte level = dis.readByte();
			if (neiDan_type == mNeiDanLi) {
				mNeiDanLiYES = new byte[level];
				mNeiDanLiNOE = new byte[maxLevel];
				mNeiDanLiGongXiao = new byte[maxLevel];
				mNeiDanLiZhangGong = new int[level];
				for (int j = 0; j < maxLevel; j++) {
					if (j < level) {
						mNeiDanLiZhangGong[j] = dis.readInt();
						mNeiDanLiYES[j] = dis.readByte(); //当前等级以开启数
					}
					mNeiDanLiNOE[j] = dis.readByte(); //当前等级能开启数		
					mNeiDanLiGongXiao[j] = dis.readByte();
				}
				continue;
			}
			if (neiDan_type == mNeiDanZhi) {
				mNeiDanZhiYES = new byte[level];
				mNeiDanZhiNOE = new byte[maxLevel];
				mNeiDanZhiGongXiao = new byte[maxLevel];
				mNeiDanZhiZhangGong = new int[level];
				for (int j = 0; j < maxLevel; j++) {
					if (j < level) {
						mNeiDanZhiZhangGong[j] = dis.readInt();
						mNeiDanZhiYES[j] = dis.readByte(); //当前等级以开启数
					}
					mNeiDanZhiNOE[j] = dis.readByte(); //当前等级能开启数		
					mNeiDanZhiGongXiao[j] = dis.readByte();
				}
				continue;
			}
			if (neiDan_type == mNeiDanJi) {
				mNeiDanJiYES = new byte[level];
				mNeiDanJiNOE = new byte[maxLevel];
				mNeiDanJiGongXiao = new byte[maxLevel];
				mNeiDanJiZhangGong = new int[level];
				for (int j = 0; j < maxLevel; j++) {
					if (j < level) {
						mNeiDanJiZhangGong[j] = dis.readInt();
						mNeiDanJiYES[j] = dis.readByte(); //当前等级以开启数
					}
					mNeiDanJiNOE[j] = dis.readByte(); //当前等级能开启数
					mNeiDanJiGongXiao[j] = dis.readByte();
				}
				continue;
			}
			if (neiDan_type == mNeiDanMin) {
				mNeiDanMinYES = new byte[level];
				mNeiDanMinNOE = new byte[maxLevel];
				mNeiDanMinGongXiao = new byte[maxLevel];
				mNeiDanMinZhangGong = new int[level];
				for (int j = 0; j < maxLevel; j++) {
					if (j < level) {
						mNeiDanMinZhangGong[j] = dis.readInt();
						mNeiDanMinYES[j] = dis.readByte(); //当前等级以开启数
					}
					mNeiDanMinNOE[j] = dis.readByte(); //当前等级能开启数		
					mNeiDanMinGongXiao[j] = dis.readByte();
				}
				continue;
			}
		}
		NeiDan();
	}

	public void NeiDan()
	{
		if (DWControlsManager.getInstance().contains(m_neidan_Frame)) {
			if (m_neidan_Frame != null) {
				DWControlsManager.getInstance().removeControl(m_neidan_Frame);
			}
		}
		m_sum_1 = 0;
		m_sum_2 = 0;
		m_sum_3 = 0;
		m_sum_4 = 0;
		// ////画布
		m_neidan_Frame = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		m_neidan_Frame.setClickClose(false);

		// ////标题
		m_neidan_tit = new DWTitle("", m_neidan_Frame);
		m_neidan_Frame.addControl(m_neidan_tit);
		m_tit_ima = new DWImageBox(m_cr_tit);
		m_tit_ima.setNearAnchor(m_neidan_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_neidan_Frame.addControl(m_tit_ima);

		// //小背景图片
		// ///小背景和画布大背景的间隙是不变的 左右 间隙是15 下面间隙是20
		m_xbj_bg = new DWBackground(
				m_neidan_Frame.getShowWidth() - 40, m_neidan_Frame.getShowHeight()
						- (m_neidan_tit.getShowHeight() - 20) - m_cr_tab_2.getHeight()
						- 20);
		m_xbj_bg.setNearAnchor(m_neidan_Frame, Tools.LEFT_TOP, Tools.LEFT_TOP,
				(m_neidan_Frame.getShowWidth() - m_xbj_bg.getShowWidth()) / 2,
				(m_neidan_tit.getShowHeight() - 20) + m_cr_tab_2.getHeight());
		m_neidan_Frame.addControl(m_xbj_bg);

		// //////////listbox图片
		m_zuo_bg = new DWBackground(m_cr_xxbj, 2 * (m_xbj_bg.getShowWidth() - 60) / 7,
				m_xbj_bg.getShowHeight() - 20);
		m_zuo_bg.setFill(false);

		// //////////////textbox图片
		m_you_bg = new DWBackground(m_cr_xxbj, 5 * (m_xbj_bg.getShowWidth() - 60) / 7,
				m_xbj_bg.getShowHeight() - 20);
		m_you_bg.setFill(false);

		m_zuo_bg.setNearAnchor(m_xbj_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,
				(m_xbj_bg.getShowWidth() - (m_zuo_bg.getShowWidth() + 20 + m_you_bg.getShowWidth())) / 2,
				(m_xbj_bg.getShowHeight() - m_zuo_bg.getShowHeight()) / 2);
		m_neidan_Frame.addControl(m_zuo_bg);

		m_you_bg.setNearAnchor(m_zuo_bg, Tools.LEFT_TOP,
				Tools.RIGHT_TOP, 20, 0);
		m_neidan_Frame.addControl(m_you_bg);

		////左下图片
		m_zuo_xiamian_bg = new DWBackground(m_cr_xiamian, m_zuo_bg.getShowWidth() - 10, 30);
		m_zuo_xiamian_bg.setNearAnchor(m_zuo_bg, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 5, -10);
		m_neidan_Frame.addControl(m_zuo_xiamian_bg);

		///左下textbox
		m_zuo_textbox = new DWLabel("  战功: " + DWGameManager.getInstance().m_role.m_zhangong);
		m_zuo_textbox.setBackgroundColor(Tools.ALPHA);
		m_zuo_textbox.setShowWideHigh(m_zuo_xiamian_bg.getShowWidth(), m_zuo_textbox.getShowHeight());
		m_zuo_textbox.setNearAnchor(m_zuo_xiamian_bg, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_neidan_Frame.addControl(m_zuo_textbox);

		///右下图片
		m_you_xiamian_bg = new DWBackground(m_cr_xiamian, m_you_bg.getShowWidth() - 10, 30);
		m_you_xiamian_bg.setNearAnchor(m_you_bg, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -5, -10);
		m_neidan_Frame.addControl(m_you_xiamian_bg);

		///右下textbox
		m_you_textbox = new DWLabel("点击空位兑换内丹，战功可通过对战活动获得");
		m_you_textbox.setNearAnchor(m_you_xiamian_bg, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_you_textbox.setBackgroundColor(Tools.ALPHA);
		m_you_textbox.setTextColor(0xFFffc001);
		m_neidan_Frame.addControl(m_you_textbox);
		////战斗属性标签
		m_label = new DWLabel("战斗属性");
		m_label.setFont(DWFont.getFont(DWFont.getDefaultFont().getFontSize() * 150 / 100));
		m_label.nameToContents();
		m_label.resetWideHigh();
		m_label.setNearAnchor(m_zuo_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,
				(m_zuo_bg.getShowWidth() - m_label.getShowWidth()) / 2, 40);
		m_label.setBackgroundColor(Tools.ALPHA);
		m_neidan_Frame.addControl(m_label);

		for (int l = 0; l < mNeiDanLiYES.length; l++) {
			m_sum_1 += mNeiDanLiYES[l] * mNeiDanLiGongXiao[l];
		}
		for (int l = 0; l < mNeiDanZhiYES.length; l++) {
			m_sum_2 += mNeiDanZhiYES[l] * mNeiDanZhiGongXiao[l];
		}
		for (int l = 0; l < mNeiDanJiYES.length; l++) {
			m_sum_3 += mNeiDanJiYES[l] * mNeiDanJiGongXiao[l];
		}
		for (int l = 0; l < mNeiDanMinYES.length; l++) {
			m_sum_4 += mNeiDanMinYES[l] * mNeiDanMinGongXiao[l];
		}

		m_sum = new long[] { m_sum_1, m_sum_2, m_sum_3, m_sum_4 };
		/////计算出的数值的算法
		DWLabel m_l = new DWLabel("测试");
		for (int n = 0; n < m_sum.length; n++) {
			m_textbox_data[n] = new DWLabel("");
			m_textbox_data[n].setShowWideHigh(m_zuo_bg.getShowWidth() - 40, m_textbox_data[n].getShowHeight());
			int m_y = (m_zuo_bg.getShowHeight() - m_label.getShowHeight() - 4 * m_l.getShowHeight()
					- m_zuo_xiamian_bg.getShowHeight() - 10 - 40) / 5;
			Tools.debugPrintln("m_y：" + m_y);
			if (n == 0) {
				m_textbox_data[n].setNearAnchor(m_zuo_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,
						(m_zuo_bg.getShowWidth() - m_textbox_data[n].getShowWidth()) / 2, m_y + m_label.getShowHeight()
								+ 40);
			}
			else {
				m_textbox_data[n].setNearAnchor(m_textbox_data[n - 1], Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, m_y);
			}
			if (n == 0) {
				m_textbox_data[n].setBackgroundColor(Tools.LILIANG);
			}
			else if (n == 1) {
				m_textbox_data[n].setBackgroundColor(Tools.ZHILI);
			}
			else if (n == 2) {
				m_textbox_data[n].setBackgroundColor(Tools.JIQIAO);
			}
			else if (n == 3) {
				m_textbox_data[n].setBackgroundColor(Tools.MINJIE);
			}
			m_neidan_Frame.addControl(m_textbox_data[n]);

			m_text_data_text[n] = new DWTextbox("   " + m_name[n] + Tools.getMoney(m_sum[n]),
					m_label.getShowWidth() + 40);
			m_text_data_text[n].setNearAnchor(m_textbox_data[n], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
			m_neidan_Frame.addControl(m_text_data_text[n]);
		}
		m_tabcontrol = new DWTabControl(m_cr_tab_1, m_cr_tab_2,
				m_zuo_bg.getShowWidth() - 18 + 20 + m_you_bg.getShowWidth(),
				m_zuo_bg.getShowHeight() + m_cr_tab_2.getHeight());
		m_tabcontrol.setNearAnchor(m_xbj_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,
				(m_xbj_bg.getShowWidth() - (m_zuo_bg.getShowWidth() + 20 + m_you_bg.getShowWidth())) / 2 + 15,
				-m_cr_tab_2.getHeight());
		m_tabcontrol.setSelectPage(0);
		m_tabcontrol.addListener(new DWListener() {

			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				m_listbox_data[m_tabcontrol.getPageIndex()].setScrollbar(0);
			}
		});
		m_neidan_Frame.addControl(m_tabcontrol);
		// /////标签页任务列表的数组 Listbox  创建listbox数组，长度是和标签长度一致，4个
		m_listbox_data = new DWListbox[m_stringname.length];
		m_lsi = new DWListSubItem[m_stringname.length][maxLevel];
		for (i = 0; i < m_stringname.length; i++) {

			if (i == 0) {
				m_list_1 = mNeiDanLiYES;
				m_list_2 = mNeiDanLiNOE;
				m_list_3 = mNeiDanLiGongXiao;
			}
			else if (i == 1) {
				m_list_1 = mNeiDanZhiYES;
				m_list_2 = mNeiDanZhiNOE;
				m_list_3 = mNeiDanZhiGongXiao;
			}
			else if (i == 2) {
				m_list_1 = mNeiDanJiYES;
				m_list_2 = mNeiDanJiNOE;
				m_list_3 = mNeiDanJiGongXiao;
			}
			else {
				m_list_1 = mNeiDanMinYES;
				m_list_2 = mNeiDanMinNOE;
				m_list_3 = mNeiDanMinGongXiao;
			}
			m_tp[i] = new DWTabPage();
			m_tp[i].setName(m_stringname[i]);

			//******右侧的内丹列表
			m_listbox_data[i] = new DWListbox(m_you_bg.getShowWidth() - 30,
					m_you_bg.getShowHeight() - 30 - m_you_xiamian_bg.getShowHeight() - 5);
			m_listbox_data[i].setNearAnchor(m_tp[i], Tools.RIGHT_TOP, Tools.RIGHT_TOP,
					-(m_you_bg.getShowWidth() - m_listbox_data[i]
							.getShowWidth()) / 2, (m_xbj_bg.getShowHeight() - m_zuo_bg.getShowHeight()) / 2 + 10);
			m_listbox_data[i].setLineSpacing(10);
			m_listbox_data[i].setShowBackgroundRect(false);
			if (m_list_2 != null) {
				DWLabel m_instead_l = new DWLabel("99级(100级)");
				for (j = 0; j < m_list_2.length; j++) {
					m_lsi[i][j] = new DWListSubItem();

					m_lv_label = new DWLabel((j + 1) + "级(" + m_list_3[j] + m_name_1[i] + ")");
					m_lv_label.setShowWideHigh(m_instead_l.getShowWidth(), DWFont.getDefaultFont().getHeight() + 5);
					m_lv_label.setNearAnchor(m_lsi[i][j], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, (40 - DWFont
							.getDefaultFont()
							.getHeight()) / 2);
					m_lv_label.setBackgroundColor(Tools.ALPHA);
					m_lsi[i][j].addControls(m_lv_label);

					///取整数，然后判断
					int m_number_1 = (m_listbox_data[i].getShowWidth() - m_lv_label.getShowWidth() - 5)
							/ (m_cr_dan[0].getWidth() + 15);
					///取余数
					int m_number_2 = (m_listbox_data[i].getShowWidth() - m_lv_label.getShowWidth() - 5)
							% (m_cr_dan[0].getWidth() + 15);

					m_dan_qian = new DWImageBox[j + 1][m_list_2[j]]; /////丹的总数，先全部部署成没亮前的，绿色的图片
					for (m = 0; m < m_list_2[j]; m++) {
						m_dan_qian[j][m] = new DWImageBox(m_cr_noeat);
						if (m == 0) {
							m_dan_qian[j][m].setNearAnchor(m_lv_label, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);
						}
						else {
							m_dan_qian[j][m].setNearAnchor(m_dan_qian[j][m - 1], Tools.LEFT_VCENTER,
									Tools.RIGHT_VCENTER, 15,
									0);
							if (m_number_2 < m_cr_dan_2.getWidth()) {
								if (m % m_number_1 == 0) {
									////上下对应位置
									m_dan_qian[j][m].setNearAnchor(m_dan_qian[j][m - m_number_1], Tools.HCENTER_TOP,
											Tools.HCENTER_BOTTOM, 0, 15);
								}
								else {
									///左右位置
									m_dan_qian[j][m].setNearAnchor(m_dan_qian[j][m - 1], Tools.LEFT_VCENTER,
											Tools.RIGHT_VCENTER, 15, 0);
								}
							}
							else {
								if (m % (m_number_1 + 1) == 0) {
									m_dan_qian[j][m].setNearAnchor(m_dan_qian[j][m - (m_number_1 + 1)],
											Tools.HCENTER_TOP,
											Tools.HCENTER_BOTTOM, 0, 15);
								}
								else {
									m_dan_qian[j][m].setNearAnchor(m_dan_qian[j][m - 1], Tools.LEFT_VCENTER,
											Tools.RIGHT_VCENTER, 15, 0);
								}
							}
						}
						m_dan_qian[j][m].addListener(m_dan_qian_lis);
						m_lsi[i][j].addControls(m_dan_qian[j][m]);
					}
					if (j < m_list_1.length) {
						for (int m = 0; m < m_list_2[j]; m++) {
							m_dan_qian[j][m].setImage(m_cr_dan_2);
						}
						if (m_list_1[j] > 0) {
							for (k = 0; k < m_list_1[j]; k++) {
								m_dan_qian[j][k].setImage(m_cr_dan[i]);
							}
						}
					}
					m_listbox_data[i].addSubItem(m_lsi[i][j]);
				}
			}
			m_tp[i].addControls(m_listbox_data[i]);
			m_tp[i].addControls(m_textbox[i]);
			m_tabcontrol.addTabPage(m_tp[i]);
		}

		// /////////退出按钮
		m_tc_ima = new DWImageBox(m_cr_tc);
		m_tc_ima.addListener(m_tc_lis);
		m_tc_ima.setTouchZoomIn(40, 40);
		m_tc_ima.setNearAnchor(m_neidan_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
		m_neidan_Frame.addControl(m_tc_ima);

		DWControlsManager.getInstance().addControl(m_neidan_Frame);
	}

	int m_length;
	boolean m_flag_eat = true;
	DWListSubItem m_save_lsi;
	DWImageBox m_donghua_ima = null;

	public void recvNeiDanEat(DataInputStream dis) throws IOException
	{

		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_内丹);
		byte state = dis.readByte();//状态  内丹显示状态0成功1失败2服用内丹已满3战功不够4等级不够
		int m_jibie_shu = m_save_listbox_item_dengji_index + 1;
		switch (state) {
			case 0:
				DWGameManager.getInstance().showToast(
						"您成功吃了1个" + m_jibie_shu + "级的" + m_stringname[m_tabcontrol.getPageIndex()],
						1000);
				int m_dengji = m_save_listbox_item_dengji_index; ///将之前保存下来的item的下标，也就是被点击的等级的下标赋值给m_dengji,相当于转化成int类型
				byte[] m_liang_data = null; //将之前的亮的数组保存起来
				byte[] m_all_data = null;
				byte[] m_gongxiao_data = null; //
				if (m_change_save_biaoqian_index == 0) {
					m_liang_data = mNeiDanLiYES;
					m_all_data = mNeiDanLiNOE;
					m_gongxiao_data = mNeiDanLiGongXiao;
				}
				else if (m_change_save_biaoqian_index == 1) {
					m_liang_data = mNeiDanZhiYES;
					m_all_data = mNeiDanZhiNOE;
					m_gongxiao_data = mNeiDanZhiGongXiao;
				}
				else if (m_change_save_biaoqian_index == 2) {
					m_liang_data = mNeiDanJiYES;
					m_all_data = mNeiDanJiNOE;
					m_gongxiao_data = mNeiDanJiGongXiao;
				}
				else {
					m_liang_data = mNeiDanMinYES;
					m_all_data = mNeiDanMinNOE;
					m_gongxiao_data = mNeiDanMinGongXiao;
				}
				////吃了一个以后应该亮的个数
				m_length = m_liang_data[m_dengji] = (byte) (m_liang_data[m_dengji] + 1);
				m_save_lsi = m_listbox_data[m_save_biaoqian_index].getListSubItem(m_dengji);
				///因为是先添加的丹的图片，所以item里的丹的图片的控件的下标就可以从0开始算
				for (byte i = 0; i < m_length; i++) {
					((DWImageBox) m_save_lsi.getControl(i + 1)).setImage(m_cr_dan[m_tabcontrol.getPageIndex()]);
				}
				if (m_donghua_ima != null && m_save_lsi.contains(m_donghua_ima))
				{
					m_save_lsi.removeControl(m_donghua_ima);
				}
				m_donghua_ima = new DWImageBox(m_dh[0]);
				m_donghua_ima.setNearAnchor(((DWImageBox) m_save_lsi.getControl(m_length)), Tools.HCENTER_VCENTER,
						Tools.HCENTER_VCENTER, 0, 0);
				m_save_lsi.addControls(m_donghua_ima);
//				for(int i=0;i<m_all_data.length;i++)
//				{
//					for(int j = 0; j<m_all_data[i];j++)
//					{
//						m_dan_qian[j].addListener(m_dan_qian_lis);
//					}
//				}
				m_flag_eat = false;
				m_timer = 0;
				/////重置左侧的textbox内的内容
				m_sum[m_change_save_biaoqian_index] += m_gongxiao_data[m_dengji];
				m_text_data_text[m_save_biaoqian_index].setText("   " + m_name[m_change_save_biaoqian_index]
						+ Tools.getMoney(m_sum[m_change_save_biaoqian_index]));

				///重置下面的战功的textbox内的内容
				m_zuo_textbox.setName("战功：" + DWGameManager.getInstance().m_role.m_zhangong);
				break;
			case 1:
				DWGameManager.getInstance().showToast("您服用" + m_jibie_shu +
						"级的" + m_stringname[m_tabcontrol.getPageIndex()] + "失败。", 1000);
				break;
			case 2:
				DWGameManager.getInstance().showToast("您服用的" + m_jibie_shu +
						"级的" + m_stringname[m_tabcontrol.getPageIndex()] + "已满。", 1000);
				break;
			case 3:
				DWGameManager.getInstance().showToast("战功不足，参与个人竞技、家族竞技、阵营战场可获得战功", 1000);
				break;
			case 4:
				DWGameManager.getInstance().showToast("您的等级不够服用" + m_jibie_shu +
						"级的" + m_stringname[m_tabcontrol.getPageIndex()] + "。", 1000);
				break;
		}
	}

	int m_change_save_biaoqian_index = 0; ////保存byte类型的标签下标
	int[] m_zhangong_xiaohao = null; ////保存每个等级消耗战功的数组
	byte[] m_lev = null;
	Bitmap m_cr_duihuan_tit = null;
	private DWListener m_dan_qian_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			Tools.debugPrintln("进入吞噬内丹的监听。");
			if (DWControlsManager.getInstance().contains(m_tishi_Frame))
			{
				if (m_tishi_Frame != null)
				{
					DWControlsManager.getInstance().removeControl(m_tishi_Frame);
				}
			}
			///画布
			if (DWGameManager.AdpaterType == DWGameManager.AD_HIGH)
			{
				m_tishi_Frame = new DWFrame(450, 400);
			}
			else
			{
				m_tishi_Frame = new DWFrame(350, 300);
			}
			m_tishi_Frame.setCentre();
			///标题
			DWTitle m_tishi_tit = new DWTitle("", m_tishi_Frame);
			DWImageBox m_duihuan_tit_ima = new DWImageBox(m_cr_duihuan_tit);
			m_duihuan_tit_ima.setNearAnchor(m_tishi_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
			///小背景
			m_tishi_xbj_bg = new DWBackground(m_tishi_Frame.getShowWidth() - 50, m_tishi_Frame
					.getShowHeight() - (m_tishi_tit.getShowHeight() - 20) - 30);
			m_tishi_xbj_bg.setNearAnchor(m_tishi_Frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

			//退出叉键
			DWImageBox m_tishi_tuichu = new DWImageBox(m_cr_tc);
			m_tishi_tuichu.setNearAnchor(m_tishi_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
			m_tishi_tuichu.setTouchZoomIn(40, 40);
			m_tishi_tuichu.addListener(m_tishi_tuichu_lis);

			/////获取被点击的标签的下标 ，等于知道吃的是那种丹
			m_save_biaoqian_index = (byte) m_tabcontrol.getPageIndex();

			///获取第几个listbox的被点击的第几个item的下标
			m_save_listbox_item_dengji_index = (byte) m_listbox_data[m_tabcontrol.getPageIndex()].getTouchIndex();
			Tools.debugPrintln("m_save_listbox_item_dengji_index=" + m_save_listbox_item_dengji_index);
			m_change_save_biaoqian_index = m_save_biaoqian_index; ////将byte类型转换成int类型，然后进行判断

			if (m_change_save_biaoqian_index == 0)
			{
				m_lev = mNeiDanLiYES;
				m_zhangong_xiaohao = mNeiDanLiZhangGong;
			}
			else if (m_change_save_biaoqian_index == 1)
			{
				m_lev = mNeiDanZhiYES;
				m_zhangong_xiaohao = mNeiDanZhiZhangGong;
			}
			else if (m_change_save_biaoqian_index == 2)
			{
				m_lev = mNeiDanJiYES;
				m_zhangong_xiaohao = mNeiDanJiZhangGong;
			}
			else if (m_change_save_biaoqian_index == 3)
			{
				m_lev = mNeiDanMinYES;
				m_zhangong_xiaohao = mNeiDanMinZhangGong;
			}

			if (m_lev.length < (m_save_listbox_item_dengji_index + 1))
			{
				DWGameManager.getInstance().showToast("您当前的级别还不能吃该等级的" +
						m_stringname[m_save_biaoqian_index] + ",希望您可以继续加油哦！^=^", 1000);
			}
			else
			{
				/////textbox
				Tools.debugPrintln("m_save_listbox_item_dengji_index=" + m_save_listbox_item_dengji_index);
				DWLabel m_tishi_textbox = new DWLabel("消耗" + m_zhangong_xiaohao[m_save_listbox_item_dengji_index] +
						"战功可凝练一颗" + (m_save_listbox_item_dengji_index + 1) + "级" + m_name_1[m_save_biaoqian_index]
						+ "之内丹，是否继续？");
				m_tishi_textbox.setBackgroundColor(Tools.ALPHA);
				m_tishi_textbox.setShowWideHigh(m_tishi_xbj_bg.getShowWidth() - 20, m_tishi_xbj_bg.getShowHeight()
						- m_cr_but_1.getHeight() - 25);
				m_tishi_textbox.setNearAnchor(m_tishi_xbj_bg, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 10);

				////兑换按钮
				DWButton m_tishi_but_queding = new DWButton("是", m_cr_but_1);
				m_tishi_but_queding.setDownImage(m_cr_but_2);
				m_tishi_but_queding.setNearAnchor(m_tishi_xbj_bg, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM,
						(m_tishi_xbj_bg.getShowWidth() - 2 * m_cr_but_1.getWidth()) / 3, -10);
				m_tishi_but_queding.addListener(m_tishi_queding_lis);

				///不兑换的按钮
				DWButton m_tishi_but_quxiao = new DWButton("否", m_cr_but_1);
				m_tishi_but_quxiao.setDownImage(m_cr_but_2);
				m_tishi_but_quxiao.setNearAnchor(m_tishi_xbj_bg, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM,
						-(m_tishi_xbj_bg.getShowWidth() - 2 * m_cr_but_1.getWidth()) / 3, -10);
				m_tishi_but_quxiao.addListener(new DWListener() {
					public void OnDoubleClick()
					{
					}

					public void OnClick()
					{
						DWControlsManager.getInstance().removeControl(m_tishi_Frame);
					}
				});

				m_tishi_Frame.addControl(m_tishi_xbj_bg);
				m_tishi_Frame.addControl(m_tishi_tit);
				m_tishi_Frame.addControl(m_duihuan_tit_ima);
				m_tishi_Frame.addControl(m_tishi_tuichu);
				m_tishi_Frame.addControl(m_tishi_textbox);
				m_tishi_Frame.addControl(m_tishi_but_queding);
				m_tishi_Frame.addControl(m_tishi_but_quxiao);
				DWControlsManager.getInstance().addControl(m_tishi_Frame);
			}
		}
	};

	private DWListener m_tishi_queding_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			DWControlsManager.getInstance().removeControl(m_tishi_Frame);
			DWGameManager.getInstance().getSendMessage().sendNeiDangEat(m_save_biaoqian_index,
					(byte) (m_save_listbox_item_dengji_index + 1));
		}
	};

	private DWListener m_tishi_tuichu_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			DWControlsManager.getInstance().removeControl(m_tishi_Frame);
		}
	};

	private DWListener m_tc_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			DWControlsManager.getInstance().removeControl(m_neidan_Frame);
			UIWindows.getInstance().m_zhanli.open_other(DWGameManager.getInstance().m_role.m_zhanli);//战力相关
		}
	};

	public void init()
	{
		m_cr_tab_1 = UIWindows.createImage("/img/newui/biaoqianye_1.gnp");// 点击前图片
		m_cr_tab_2 = UIWindows.createImage("/img/newui/biaoqianye_2.gnp");// 点击后图片
		m_cr_tc = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp"); // 退出叉键按钮的图片
		m_cr_dan[0] = UIWindows.createImage("/img/newui/lidan_1.gnp"); ////点击后
		m_cr_dan[1] = UIWindows.createImage("/img/newui/zhidan_1.gnp"); ////点击后
		m_cr_dan[2] = UIWindows.createImage("/img/newui/jidan_1.gnp"); ////点击后
		m_cr_dan[3] = UIWindows.createImage("/img/newui/mindan_1.gnp"); ////点击后
		m_cr_dan_2 = UIWindows.createImage("/img/newui/neidanndtb_1.gnp"); ////点击前的丹的图 ，可以吃的丹
		m_cr_xiamian = UIWindows.createImage("/img/newui/jinengtf_1.gnp"); ////最下面绿色横条的图片
		m_cr_but_1 = UIWindows.createImage("/img/newui/anniu_5.gnp");
		m_cr_but_2 = UIWindows.createImage("/img/newui/anniu_5ax.gnp");
		m_cr_xxbj = UIWindows.createImage("/img/newui/beibaobj_1.gnp");////小背景里面的2个小小背景呢
		m_cr_tit = UIWindows.createImage("/img/newui/neidan_1.gnp");
		m_cr_noeat = UIWindows.createImage("/img/newui/neidanndtb_2.gnp");//不能吃的内丹，级别不够的
		m_cr_duihuan_tit = UIWindows.createImage("/img/newui/ninglian_1.gnp"); ///兑换内丹的标题

		//凝练效果图的图片数组
		m_dh[0] = UIWindows.createImage("/img/newui/neidanfg_1.gnp");
		m_dh[1] = UIWindows.createImage("/img/newui/neidanfg_2.gnp");
		m_dh[2] = UIWindows.createImage("/img/newui/neidanfg_3.gnp");
		m_dh[3] = UIWindows.createImage("/img/newui/neidanfg_4.gnp");
		m_dh[4] = UIWindows.createImage("/img/newui/neidanfg_5.gnp");
		m_dh[5] = UIWindows.createImage("/img/newui/neidanfg_6.gnp");
		m_dh[6] = UIWindows.createImage("/img/newui/neidanfg_7.gnp");
		m_dh[7] = UIWindows.createImage("/img/newui/neidanfg_8.gnp");
		m_dh[8] = UIWindows.createImage("/img/newui/neidanfg_9.gnp");
	}

	public void open(byte index)
	{
		NeiDan();
	}

	public void close(byte index)
	{
	}

	public void dispose()
	{
	}

	Bitmap m_dh[] = new Bitmap[9];
	private final int m_arc1_all = m_dh.length + 1;
	private final int m_arc1_speed = 2;
	private int m_timer = 0;

	public void logic()
	{
		if (DWControlsManager.getInstance().contains(m_neidan_Frame)) {
			if (m_neidan_Frame != null) {
				if (!m_flag_eat) {
					int way = (m_timer % (m_arc1_all * m_arc1_speed)) / m_arc1_speed;
					if (way >= 0 && way < m_dh.length) {
//						((DWImageBox) m_save_lsi.getControl(m_length)).setImage(m_dh[way]);
						m_donghua_ima.setImage(m_dh[way]);
					}
					else if (way == m_dh.length) {
//						((DWImageBox) m_save_lsi.getControl(m_length)).setImage(m_cr_dan[m_tabcontrol.getPageIndex()]);
						m_save_lsi.removeControl(m_donghua_ima);
						m_flag_eat = true;
						m_timer = 0;
					}
					Tools.debugPrintln("way:" + way);
				}
			}
		}
		if (++m_timer > 1000000) {
			m_timer = 0;
		}
	}

	public DWTabControl tabcontrol()
	{
		if (DWControlsManager.getInstance().contains(m_neidan_Frame) && m_tabcontrol != null) {
			return m_tabcontrol;
		}
		return null;
	}

	public DWImageBox getLiDanImage()
	{
		if (DWControlsManager.getInstance().contains(m_neidan_Frame)
				&& m_tabcontrol.getPageIndex() == 0 && m_dan_qian != null) {
			return m_dan_qian[0][0];
		}
		return null;
	}

	public DWImageBox getZhiDanImage()
	{
		if (DWControlsManager.getInstance().contains(m_neidan_Frame)
				&& m_tabcontrol.getPageIndex() == 1 && m_dan_qian != null) {
			return m_dan_qian[1][0];
		}
		return null;
	}

	public DWImageBox getJiDanImage()
	{
		if (DWControlsManager.getInstance().contains(m_neidan_Frame)
				&& m_tabcontrol.getPageIndex() == 2 && m_dan_qian != null) {
			return m_dan_qian[2][0];
		}
		return null;
	}

	public DWImageBox getMinDanImage()
	{
		if (DWControlsManager.getInstance().contains(m_neidan_Frame)
				&& m_tabcontrol.getPageIndex() == 3 && m_dan_qian != null) {
			return m_dan_qian[3][0];
		}
		return null;
	}
}
